﻿<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<ConsumerLevelInfo>" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Methods in consumer level</title>
    <link href="../../Content/Site.css" rel="stylesheet" type="text/css" />
    <link type="text/css" href="<%= Url.Content("~/Content/fg.menu/fg.menu.css") %>"
        media="screen" rel="stylesheet" />
    <link type="text/css" href="<%= Url.Content("~/Content/fg.menu/theme/ui.all.css") %>"
        media="screen" rel="stylesheet" />
    <link href="<%= Url.Content("~/Content/nyroModal.css") %>" rel="stylesheet" type="text/css" />
    <link href="<%= Url.Content("~/Content/nyroModal.full.css") %>" rel="stylesheet"
        type="text/css" />

    <script type="text/javascript" language="javascript" src="<%= Url.Content("~/Scripts/Calendar.js") %>"></script>

    <script type="text/javascript" language="javascript" src="<%= Url.Content("~/Scripts/jquery-1.4.1.js") %>"></script>

    <script type="text/javascript" language="javascript" src="<%= Url.Content("~/Scripts/jquery-1.4.1.min.js") %>"></script>

    <script type="text/javascript" language="javascript" src="<%= Url.Content("~/Scripts/fg.menu.js") %>"></script>

    <script type="text/javascript" language="javascript" src="<%= Url.Content("~/Scripts/jquery.nyroModal-1.6.2.pack.js") %>"></script>

</head>
<body>
    <div id="main">
        <table border="0" cellspacing="0" width="100%">
            <tr>
                <td width="150">
                    Consumer Level
                </td>
                <td>
                    <% =Html.TextBox("txtCONSUMER_LEVEL", Model.CONSUMER_LEVEL, new { @style = "width:250px",@disabled="disabled"})%>
                </td>
            </tr>
            <tr>
                <td width="150">
                    Consumer Level Name
                </td>
                <td>
                    <% =Html.TextBox("txtCONSUMER_LEVEL_NAME", Model.CONSUMER_LEVEL_NAME, new { @style = "width:250px", @disabled = "disabled" })%>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <fieldset>
                        <legend>Methods</legend>
                        <div>
                            <ul style="list-style-type: none;">
                                <li>
                                    <input type="button" id="btnSaveTop" name="btnSaveTop" value="Save Setting" />
                                </li>
                                <li>
                                    <hr />
                                </li>
                                <%
                                    int num = 1;
                                    foreach (MethodInfo m in ViewData["Methods"] as IList<MethodInfo>)
                                    {
                                        string chk = "";
                                        foreach (MethodInConsumerLevelInfo select_m in ViewData["SelectedMethods"] as IList<MethodInConsumerLevelInfo>)
                                        {
                                            if (m.METHOD_NAME == select_m.MethodInConsumerLevelPK.METHOD_NAME)
                                            {
                                                chk = "checked";
                                                break;
                                            }
                                        }        
                                %>
                                <li>
                                    <input type="checkbox" id="chklistMethod_<%=num %>" name="chklistMethod" value="<%= m.METHOD_NAME%>"
                                        <%=chk %> />
                                    <label for="chklistMethod_<%=num %>">
                                        <%= m.METHOD_NAME%>
                                    </label>
                                </li>
                                <%
                                    num++;
                                    }
                                %>
                                <li>
                                    <hr />
                                </li>
                                <li>
                                    <input type="button" id="btnSaveBottom" name="btnSaveBottom" value="Save Setting" />
                                </li>
                            </ul>
                        </div>
                    </fieldset>
                </td>
            </tr>
        </table>
    </div>

    <script type="text/javascript" language="javascript">

        //json: Submit
        $().ready(function() {
            $("#btnSaveTop").click(function() {
                AjaxSaveSetting();
            })
        })

        $().ready(function() {
            $("#btnSaveBottom").click(function() {
                AjaxSaveSetting();
            })
        })

        function AjaxSaveSetting() {

            if (confirm('Are you sure submit?')) {

                var consumer_level = $("input[name='txtCONSUMER_LEVEL']").val();
                var str_methods = "";

                $("input[name='chklistMethod'][@checked]").each(function() { //由于复选框一般选中的是多个,所以可以循环输出
                    if ($(this).attr("checked")) {
                        str_methods += $(this).val() + ",";
                    }
                });

                //alert(str_methods);

                $("input[name='btnSaveTop']")[0].disabled = "disabled";
                $("input[name='btnSaveTop']")[0].value = "Save Setting...";
                $("input[name='btnSaveBottom']")[0].disabled = "disabled";
                $("input[name='btnSaveBottom']")[0].value = "Save Setting...";

                $.post("/Consumer/AjaxSaveMethodsToLevel?" + new Date(), {
                    Action: "post",
                    consumer_level: consumer_level,
                    str_methods: str_methods
                }, function(result) {
                    if (result.FLAG) {
                        alert(result.DESC);
                        $("input[name='btnSaveTop']")[0].disabled = "";
                        $("input[name='btnSaveTop']")[0].value = "Save Setting";
                        $("input[name='btnSaveBottom']")[0].disabled = "";
                        $("input[name='btnSaveBottom']")[0].value = "Save Setting";
                    }
                    else {
                        alert(result.DESC);
                        $("input[name='btnSaveTop']")[0].disabled = "";
                        $("input[name='btnSaveTop']")[0].value = "Save Setting";
                        $("input[name='btnSaveBottom']")[0].disabled = "";
                        $("input[name='btnSaveBottom']")[0].value = "Save Setting";
                    }
                })
            }
        }
    </script>

</body>
</html>
